#include "HDF5GroupObject.h"

CHDF5GroupObject::CHDF5GroupObject()
:h5_file(NULL),errMsg(""){
}
CHDF5GroupObject::~CHDF5GroupObject()
{
	if (h5_file!=NULL)
	{
		delete h5_file;
	}
}

bool CHDF5GroupObject::isGroupExist(const H5std_string& location)
{

	try
	{
		Exception::dontPrint();
		h5_file->openGroup(location);
	}
	// catch failure caused by the H5File operations
	catch( FileIException error )
	{
		return false;
	}
	return true;
}

int CHDF5GroupObject::createGroups(const H5std_string& location,const H5std_string& groupName)
{
	int res=0;
	try
	{
		Exception::dontPrint();
		if (isGroupExist(location))
		{
			H5std_string path(location);
			path.append("/");
			path.append(groupName);
			Group group(h5_file->createGroup(path));
			res=1;
			
		}
	}
	// catch failure caused by the H5File operations
	catch( FileIException error )
	{
		errMsg=error.getDetailMsg();
	}

	// catch failure caused by the Group operations
	catch( GroupIException error )
	{
		errMsg=error.getDetailMsg();
	}

	return res;
}

H5std_string CHDF5GroupObject::GetErrMsg()const
{
	return errMsg;
}